package com.leyou.goods.item.dao;

import com.leyou.goods.item.pojo.Brand;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandDao extends Mapper<Brand> {
    @Select("SELECT * FROM tb_brand")
    public List<Brand> findAll();


    @Insert("INSERT INTO tb_category_brand(category_id, brand_id) VALUES (#{cid},#{bid})")
    public int insertBrandAndCategory(@Param("cid") Long cid, @Param("bid") Long bid);

    @Select("SELECT tb_brand.name 'name',tb_brand.id 'id' FROM  tb_brand , tb_category , tb_category_brand WHERE tb_brand.id = tb_category_brand.brand_id AND tb_category.id = tb_category_brand.category_id AND  tb_category_brand.category_id=#{cid}")
    List<Brand> getCbById(Long cid);
    @Select("SELECT b.* from tb_brand b INNER JOIN tb_category_brand cb on b.id=cb.brand_id where cb.category_id=#{cid}")
    List<Brand> selectBrandByCid(Long cid);
}
